/**
 * 初始化部门详情对话框
 */
var TestQuestionsInfoDlg = {
    TestQuestionsInfoData : {},
    zTreeInstance : null,
    validateFields: { }
};

/**
 * 清除数据
 */
TestQuestionsInfoDlg.clearData = function() {
    this.TestQuestionsInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
TestQuestionsInfoDlg.set = function(key, val) {
    this.TestQuestionsInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
TestQuestionsInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
TestQuestionsInfoDlg.close = function() {
    parent.layer.close(window.parent.TestQuestions.layerIndex);
}

/**
 * 收集数据
 */
TestQuestionsInfoDlg.collectData = function() {
    this.set('id').set('testTitle').set('titleType').set('optionsA').set('optionsB').set('optionsC').set('optionsD')
        .set('optionsE').set('optionsF').set('correctAnswer').set('remark');
}

/**
 * 验证数据是否为空
 */
TestQuestionsInfoDlg.validate = function () {
    $('#deptInfoForm').data("bootstrapValidator").resetForm();
    $('#deptInfoForm').bootstrapValidator('validate');
    return $("#deptInfoForm").data('bootstrapValidator').isValid();
}
TestQuestionsInfoDlg.importSubmit = function () {
    alert($("#uploadfile").val(""));
}
/**
 * 提交添加
 */
TestQuestionsInfoDlg.addSubmit = function() {
    this.clearData();
    this.collectData();
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/testQuestions/add", function(data){
        Feng.success("添加成功!");
        window.parent.TestQuestions.table.refresh();
        TestQuestionsInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.TestQuestionsInfoData);
    ajax.start();
}
TestQuestionsInfoDlg.downLoadExcel = function () {
    location.href=Feng.ctxPath +'/testQuestions/getTemplateExcel?';
};
/**
 * 提交修改
 */
TestQuestionsInfoDlg.editSubmit = function() {
    this.clearData();
    this.collectData();
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/testQuestions/update", function(data){
        Feng.success("修改成功!");
        window.parent.TestQuestions.table.refresh();
        TestQuestionsInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.TestQuestionsInfoData);
    ajax.start();
}
//初始化数据
TestQuestionsInfoDlg.initData = function () {
    //状态单选
    var seletitleType = $('#ititleType').val();
    if ($('#id').val() != "") {
        $("#titleType option[value=" + seletitleType + "]").attr("selected", "selected");
    }
}
function onBodyDown(event) {
    if (!(event.target.id == "menuBtn" || event.target.id == "parentDeptMenu" || $(
            event.target).parents("#parentDeptMenu").length > 0)) {
        TestQuestionsInfoDlg.hideDeptSelectTree();
    }
}

$(function() {
    Feng.initValidator("deptInfoForm", TestQuestionsInfoDlg.validateFields);
    var ztree = new $ZTree("parentDeptMenuTree", "/dept/tree");
    ztree.bindOnClick(TestQuestionsInfoDlg.onClickDept);
    ztree.init();
    TestQuestionsInfoDlg.initData();
    TestQuestionsInfoDlg.zTreeInstance = ztree;
});
